package com.ruoyi.ly.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.ly.domain.LyMerchantActivities;
import com.ruoyi.ly.service.ILyMerchantActivitiesService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商家活动Controller
 * 
 * @author liuyan
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/activities")
public class LyMerchantActivitiesController extends BaseController
{
    @Autowired
    private ILyMerchantActivitiesService lyMerchantActivitiesService;

    /**
     * 查询商家活动列表
     */
    @RequiresPermissions("ly:activities:list")
    @GetMapping("/list")
    public TableDataInfo list(LyMerchantActivities lyMerchantActivities)
    {
        startPage();
        List<LyMerchantActivities> list = lyMerchantActivitiesService.selectLyMerchantActivitiesList(lyMerchantActivities);
        return getDataTable(list);
    }
    // <!--商家查询自己已上架的活动-->
    @RequiresPermissions("ly:activities:list")
    @GetMapping("/list1")
    public TableDataInfo list1(LyMerchantActivities lyMerchantActivities)
    {
        startPage();
        List<LyMerchantActivities> list = lyMerchantActivitiesService.selectLyMerchantActivitiesList1(lyMerchantActivities);
        return getDataTable(list);
    }
    //    未上架
    @RequiresPermissions("ly:activities:list")
    @GetMapping("/list2")
    public TableDataInfo list2(LyMerchantActivities lyMerchantActivities)
    {
        startPage();
        List<LyMerchantActivities> list = lyMerchantActivitiesService.selectLyMerchantActivitiesList2(lyMerchantActivities);
        return getDataTable(list);
    }
    /**
     * 导出商家活动列表
     */
    @RequiresPermissions("ly:activities:export")
    @Log(title = "商家活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LyMerchantActivities lyMerchantActivities)
    {
        List<LyMerchantActivities> list = lyMerchantActivitiesService.selectLyMerchantActivitiesList(lyMerchantActivities);
        ExcelUtil<LyMerchantActivities> util = new ExcelUtil<LyMerchantActivities>(LyMerchantActivities.class);
        util.exportExcel(response, list, "商家活动数据");
    }

    /**
     * 获取商家活动详细信息
     */
    @RequiresPermissions("ly:activities:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(lyMerchantActivitiesService.selectLyMerchantActivitiesById(id));
    }

    //    多表查询
    @RequiresPermissions("ly:activities:query")
    @GetMapping(value = "/activities/{id}")
    public AjaxResult getInfo1(@PathVariable("id") Long id)
    {
        return success(lyMerchantActivitiesService.selectLyMerchantActivitiesByIds(id));
    }

    //    多表查询test
//    @RequiresPermissions("ly:activities:query")
//    @GetMapping(value = "/activities/tt/{mid}")
//    public AjaxResult getInfo2(Long mid)
//    {
//        return success(lyMerchantActivitiesService.selectLyMerchantActivitiesByIdss(mid));
//    }
    /**
     * 新增商家活动
     */

    @RequiresPermissions("ly:activities:add")
    @Log(title = "商家活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LyMerchantActivities lyMerchantActivities)
    {

        return toAjax(lyMerchantActivitiesService.insertLyMerchantActivities(lyMerchantActivities));
    }

    /**
     * 修改商家活动
     */
    @RequiresPermissions("ly:activities:edit")
    @Log(title = "商家活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LyMerchantActivities lyMerchantActivities)
    {
        return toAjax(lyMerchantActivitiesService.updateLyMerchantActivities(lyMerchantActivities));
    }
    //下架单个活动
    @RequiresPermissions("ly:activities:edit")
    @Log(title = "商家活动", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/xiajia/{id}")
    public AjaxResult edit1(LyMerchantActivities lyMerchantActivities)
    {
        return toAjax(lyMerchantActivitiesService.xiugaisendStatus(lyMerchantActivities));
    }

    /**
     * 删除商家活动
     */
    @RequiresPermissions("ly:activities:remove")
    @Log(title = "商家活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {

        return toAjax(lyMerchantActivitiesService.deleteLyMerchantActivitiesByIds(ids));
    }
    @RequiresPermissions("ly:activities:remove")
    @Log(title = "商家活动", businessType = BusinessType.DELETE)
    @DeleteMapping("/byid/{id}")
    public AjaxResult remove1(@PathVariable Long id)
    {

        return toAjax(lyMerchantActivitiesService.deleteLyMerchantActivitiesById(id));
    }
}
